import cgi
import os
import logging
import base64
import authorization

from collections import deque
from xml.etree import ElementTree as ET
from google.appengine.ext.webapp import template
from models import model
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class Requests(webapp.RequestHandler):
    def post(self, board_name):
        headers = self.request.headers
        user = authorization.authorization(headers)
        logging.error(user)
        if(user == ""):
          self.error(403)
        else:
          board = model.Boards.all().filter('Name = ', board_name)
          logging.error(board.count())
          logging.error(board)
          if(board.count() == 0):
            self.error(204)
          else:
            if(board[0].Status != "OPEN"):
              self.error(401)
            else:
              board_update = board[0]
              board_update.Invitee = user
              board_update.Status = "FULL"
              board_update.put()
